import React from "react";

import { ajax ,showResultMessage,isNotNull} from '../../common';

import UIForm from '../../uicomponents/UIForm';

/** 
 *产品基本信息编辑表单
*/
export default class productDefineFormPanel extends React.Component {

    constructor(props) {
        super(props);
    }
    
    componentDidMount(){
        if(isNotNull(this.props.onMount)){
            this.props.onMount(this.dataFormRef,this);
        }
    }
    
    setFormData = (formData) => {
        this.dataFormRef.setFormData(formData);
    }
    
    doSave = (extendData,callback) => {
        this.dataFormRef.getFormData((formData) => {
                const submitData = isNotNull(extendData) ? {...formData,...extendData} : formData;
                const result = {};
                ajax('PRODUCT/REQ/ProductDefine/saveProductDefine', submitData).then(function (data) {
                        result.success = true;
                        result.data = data;
                    }).catch(function (reason) {
                        result.success = false;
                        result.message = reason;
                    }).finally(() => {
                        if(isNotNull(callback)){
                            callback(result);
                        }
                    });
            }
        );
    }
    
  
	
		
	/** Event Handle Code Example
	
	actionHandler = (actionEvent,panelInstance) => {

		return {
			
													
			doSave : () => {
			},
												
		};
	}
	
	
	*/

    
    actionHandler = (actionEvent) => {
	
	    const {actionHandler} = this.props;
	    
	    if(isNotNull(actionHandler)){
	        return actionHandler(actionEvent,this);
	    }
	    else{
	        return null;
	    }
	}

    render() {
        return (
            <UIForm {...this.props}
                wrappedComponentRef={(inst) => this.dataFormRef = inst}
                formConfigId="ProductUI:productDefineEditForm"
                actionGroupId="ProductUI:saveActionGroup"
                actionHandler={this.actionHandler}
            />
            
        );
    }
}